package com.feicheng.controller.admin;

import com.alibaba.fastjson.JSONObject;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.service.a.FKcService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/kc")
public class KcController {
    @Autowired
    FKcService kcService;

    @GetMapping("/page")
    public ResultInfo getByPage(@RequestParam(defaultValue = "1") Integer current,
                                @RequestParam(defaultValue = "12") Integer size,
                                String searchKey) {
        JSONObject param = new JSONObject();
        param.put("current", current);
        param.put("size", size);
        param.put("kcname", searchKey);
        kcService.getKcByPage(param);
        return ResultInfo.success(param.get("akechengs"));
    }

    @GetMapping("/info")
    public ResultInfo newInfo(Integer kcid) {
        JSONObject param = new JSONObject();
        param.put("kcid", kcid);
        param = kcService.getKc(param);
        return ResultInfo.success(param);
    }

    @GetMapping("/kclx/list")
    public ResultInfo getLxList() {
        return ResultInfo.success(kcService.getKclxList(new JSONObject()));
    }

    @GetMapping("/kclx/tree")
    public ResultInfo getKclxTree() {
        return ResultInfo.success(kcService.getKclxTree());
    }

    @PostMapping("/kclx/info")
    public ResultInfo newKclx(@RequestBody JSONObject param) {
        param = kcService.newKclx(param);
        return ResultInfo.success();
    }

    @DeleteMapping("/kclx/info")
    public ResultInfo removeKclx(String kclxid) {
        JSONObject param = new JSONObject();
        param.put("kclxid", kclxid);
        param = kcService.deleteKclx(param);
        return ResultInfo.success(param);
    }

}